constructive algorithms sortings

Please click on ads to support us..

C++ Code:

#include "bits/stdc++.h"
using namespace std;

#define ll  			long long int
#define nl			    "\n"
#define yes 			cout << "YES\n"
#define no  			cout << "NO\n"
#define lower(s)        transform(s.begin(), s.end(), s.begin(), ::tolower);
#define upper(s)        transform(s.begin(), s.end(), s.begin(), ::toupper);
#define vin 			vector<int>
#define vln 			vector<ll>
#define pb  			push_back
#define all(x) 			(x).begin(), (x).end()
#define rall(x) 		(x).rbegin(), (x).rend()
#define FastIo 		    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)


const ll N = 1e6 + 1 ;
const ll MOD = 1e9 + 7 ;


int main()
{
        
        FastIo ;
        
        int t = 1 ;
        cin >> t ;
        while(t--){

            ll n, m, k, q ;
            cin >> n ;
            vin v(n), a;
            for(int i=0; i<n; i++){
                cin >> v[i];
            }
            

            vector<pair<int, int>> p(n), p2 ;
            
            for(int i=0; i<n; i++){
                p[i] = {v[i], i}; 
            }
            sort(all(p));
            vector<int> ans(n);
            int mx = n ;
            for(int i=0; i<n; i++){
                ans[p[i].second] = mx ;
                mx--;
            }
            for(auto u : ans){
                cout << u << ' ';
            }cout << endl;
            
            
        }

	return 0 ;
}



/*

check negative value then mx = -1e9
check ll and int

sieve----

    isPrime[0] = isPrime[1] = 1 ;
    for(int i=2; i<=N; i+=2){
        isPrime[i] = 1 ;
    }
    isPrime[2] = 0 ;
    for(int i=3; i*i<=N; i+=2){
        if(isPrime[i] == 0){
            for(int j=i*i; j<=N; j+=i){
                isPrime[j] = 1 ;
            }
        }   
    }

*/



Comments

Submit
0 Comments
More Questions

1091A - New Year and the Christmas Ornament
1352B - Same Parity Summands
1102A - Integer Sequence Dividing
630B - Moore's Law
1004A - Sonya and Hotels
1680B - Robots
1690A - Print a Pedestal (Codeforces logo)
1295A - Display The Number
1077A - Frog Jumping
1714G - Path Prefixes
1369C - RationalLee
289B - Polo the Penguin and Matrix
1716A - 2-3 Moves
1670B - Dorms War
1716B - Permutation Chain
987A - Infinity Gauntlet
1676G - White-Black Balanced Subtrees
1716D - Chip Move
1352F - Binary String Reconstruction
1487B - Cat Cycle
1679C - Rooks Defenders
56A - Bar
1694B - Paranoid String
35A - Shell Game
1684A - Digit Minimization
43B - Letter
1017A - The Rank
1698B - Rising Sand
235A - LCM Challenge
1075B - Taxi drivers and Lyft